package cn.chenxiejia;

import org.jsoup.Jsoup;

import java.io.IOException;
import java.util.Random;
import java.util.regex.Pattern;

/***
 * @program: maven
 * @ClassName: String2
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/1/15 16:55
 * @version : V1.0
 */
public class String2 {
    public static void main(String[] args) throws IOException {
        String a = "helloworld";
        var b = a.toCharArray();
        System.out.println(b.length / 2);
        for (int i = 0; i < b.length / 2; i++) {
            var s = b[i];
            b[i] = b[b.length - 1 - i];
            b[b.length - 1 - i] = s;
        }
        for (char c : b) {
            System.out.print(c);
        }


        System.out.println("*".repeat(20));
        StringBuilder sb = new StringBuilder();
        for (int i = b.length - 1; i >= 0; i--) {
            sb.append(b[i]);
        }
        System.out.println(sb);

        String ss = "javadkfjavajldsjavaksdjfjavajlkjsdfjavajsadjfsdfjavajld;safjjavajl;sdjfjjavajl;sadfjjvavjsl;dfjjava";
        String str = "java";
        int count = 0;
        for (int i = 0; i < ss.length(); i++) {
            if (ss.indexOf(str, i) != -1) {
                count++;
                i = ss.indexOf(str, i);
                i += str.length();
            }
        }
        System.out.println(count);
        String i = "1234567891000000";
        StringBuilder sss = new StringBuilder(i);
        for (int j = sss.length() - 3; j > 0; j -= 3) {
            sss.insert(j, ",");
        }
        System.out.println(sss);


        String str1 = "0123456789_-=+'\",`~!@#$%^&*()abcdefghijklmnolpqrstuvwxyzABCDEFGHIJKLMNOLPQRSTUVWXYZ";
        Random random = new Random();
        StringBuilder s1 = new StringBuilder();
        for (int j = 0; j < 32; j++) {
            s1.append(str1.toCharArray()[random.nextInt(str1.length())]);
        }
        System.out.println(s1);
        System.out.println(s1.length());
        System.out.println("*".repeat(20));

        var i2 = "18338614928";
        String s = "https://ip138.com/mobile.asp?mobile=" + i2 + "&action=mobile";
        String s2 = Jsoup.connect(s).get().toString();
        Pattern pattern = Pattern.compile("<span>(.*[\\u4e00-\\u9fa5]+市)</span>");
        var mm = pattern.matcher(s2);
        if (mm.find()) {

            System.out.println(mm.group(1).replace("&nbsp;", " "));
        }
    }
}
